home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / PROTMODE / PROTECT.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-08-03  |  4.0 KB  |  89 lines

  1. ;This handles the protected mode jump for Isnt.
  2. ;(C) 1995 American Eagle Publications, Inc. All rights reserved.
  3.  
  4. ;Definitions for use in this program
  5. IOMAP_SIZE      EQU     801H
  6. VIDEO_SEG       EQU     0B800H          ;segment for video ram
  7. STACK_SIZE      EQU     500H            ;size of stacks used in this pgm
  8. NEW_INT_LOC     EQU     20H             ;new location for base of hardware interrupts
  9.  
  10. INCLUDE PM_DEFS.ASM     ;include protected mode definitions
  11.  
  12. ;Definition for jump into protected mode
  13. HI_MEMORY       DD      OFFSET V86_LOADER
  14.                 DW      CODE_1_SEL
  15.  
  16. OLDSTK          DD      ?                       ;old stack pointer from slips
  17.  
  18. ;This routine actually performs the protected mode jump. It initializes tables,
  19. ;moves the code to high memory, and then jumps to the V86_LOADER in the TASK1
  20. ;segment. Control returns in V86 mode to the routine VIRTUAL below.
  21. GO_PROTECTED:
  22.                 mov     ax,cs                   ;initialize variables for program
  23.                 mov     ds,ax
  24.                 mov     WORD PTR [OLDSTK],sp    ;save the stack
  25.                 mov     WORD PTR [OLDSTK+2],ss
  26.                 call    SETUP_IDT               ;initialize IDT
  27.                 call    SETUP_TASK2             ;initialize Task State Seg 2
  28.                 call    MOVE_CODE               ;move code to 110000H
  29.                 cli
  30.                 call    CHANGE_INTS             ;Move 8259 controller bases
  31.                 call    GATE_A20                ;Turn A20 line on
  32.                 mov     ah,1                    ;this flushes something on
  33.                 int     16H                     ;some 386SXs or they crash
  34.                 xor     eax,eax
  35.                 push    eax
  36.                 popfd                           ;clear flags
  37.                 lgdt    FWORD PTR GDT_PTR       ;set up GDT register
  38.                 lidt    FWORD PTR IDT_PTR       ;set up IDT register
  39.                 mov     eax,cr0
  40.                 or      eax,1
  41.                 mov     cr0,eax                 ;set protected mode bit
  42.                 jmp     FWORD PTR cs:[HI_MEMORY];go to high memory
  43.  
  44. ;This routine returns with Z set if the processor is in real mode, and NZ if
  45. ;it is in V86 mode.
  46. IS_V86:
  47.                 PUSHF                           ;first check for V86 mode
  48.                 POP     AX
  49.                 OR      AX,3000H
  50.                 mov     bx,ax
  51.                 PUSH    AX
  52.                 POPF                            ;Pop flags off Stack
  53.                 PUSHF                           ;Push flags on Stack
  54.                 POP     AX
  55.                 cmp     ax,bx
  56.                 jnz     VMODE
  57.                 AND     AX,0CFFFH
  58.                 mov     bx,ax
  59.                 PUSH    AX
  60.                 POPF                            ;Pop flags off Stack
  61.                 PUSHF                           ;Push flags on Stack
  62.                 POP     AX
  63.                 cmp     ax,bx
  64. VMODE:          ret
  65.  
  66. INCLUDE SETUPROT.ASM    ;protected mode setup routines called above
  67.  
  68. ;End of code to get to protected mode
  69. ;*******************************************************************************
  70.  
  71. ;******************************************************************************
  72. ;The following code is executed in V86 mode after control is passed here from
  73. ;the protected mode task switch. It just turns interrupts back on and returns
  74. ;control to the calling program.
  75. ;******************************************************************************
  76. VIRTUAL:
  77.                 cli
  78.                 mov     al,0                    ;unmask hardware interrupts
  79.                 out     21H,al
  80.                 mov     ax,cs                   ;set up segments
  81.                 mov     ds,ax
  82.                 mov     es,ax
  83.                 lss     sp,[OLDSTK]             ;and the stack
  84.                 sti                             ;enable interrupts
  85.                 ret                             ;return to caller in Isnt
  86.  
  87. ;End of V86 mode code
  88. ;*******************************************************************************
  89.